package br.com.rodrigo.utils;

import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.com.rodrigo.constants.Constants;

public class ConnectionUtils
{

    private static final java.lang.String CONNECTION_FACTORY_JNDI_NAME = "jms/ConnectionFactory";

    public static QueueConnection getQueueConnection() throws NamingException, JMSException
    {
        InitialContext ic = new InitialContext();

        Context envContext = (Context) ic.lookup(Constants.CONTEXT);

        /** FABRICA DE CONEXOES */
        QueueConnectionFactory factory = (QueueConnectionFactory) envContext.lookup(CONNECTION_FACTORY_JNDI_NAME);

        /** CONEXAO */
        QueueConnection conn = factory.createQueueConnection();

        return (QueueConnection) conn;

    }
}
